package org.javamap;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Stroke;



public abstract class Overlay implements java.io.Serializable
{
	protected Overlay() {}
	
	public abstract void draw(java.awt.Graphics2D g2d, JavaMapPane jmp);
	
	public final String getName() { return name; }
	public final void setName(String name) { this.name = name; }
	
	public final void addLocation(Location loc)
	{ locations.add(loc); }
	
	public final Location getLocation(int index)
	{ return locations.get(index); }
	
	public final int getLocationCount() { return locations.size(); }
	
	public final void removeLocation(int index) { locations.remove(index); }
	
	public final int findLocation(Point p, JavaMapPane jmp)
	{
		Point locPoint = new Point();
		
		for (int ii = 0; ii < locations.size(); ++ii) {
			Location loc = locations.get(ii);
			
			jmp.locationToPoint(loc, jmp.getDepth(), locPoint);
			if (locPoint.distanceSq(p) < selectionRadiusSq) return ii;
		}
		
		return -1;			
	}
	
	/**
	  * Some portion of the overlay is selected, and should be drawn in a 
	  *  highlighted state.
	  */
	public final void selectLocation(int index)
	{
		selectedIndex = index;	
	}
	
	/**
	  * Returns the index of the currently selected index, or -1.
	  */
	public final int getSelectedIndex() { return selectedIndex; }
	
	public final String toString() { return name; }
		
	private final java.util.ArrayList<Location> locations 
			= new java.util.ArrayList<Location>();
	private int selectedIndex = -1, selectionRadiusSq = 100;
	private String name;
}

